package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import java.util.*;

@Controller
public class HelloController {

    @GetMapping("/basic")
    public String test(Model model) {


        //1.纯文本形式的参数
        model.addAttribute("name", "freemarker");
        //2.实体类相关的参数

        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        model.addAttribute("stu", student);

        return "01-basic";
    }

    @GetMapping("/list")
    public String list(Model model) {
        Student stu1 = new Student();
        stu1.setName("陈明");
        stu1.setAge(18);
        stu1.setMoney(11.1f);
        Student stu2 = new Student();
        stu2.setName("小红");
        stu2.setMoney(200.1f);
        stu2.setAge(19);
        List<Student> stus = new ArrayList<Student>();
        stus.add(stu1);
        stus.add(stu2);
        //空值处理
//        model.addAttribute("stus", students);
        Map<String, Student> stuMap = new HashMap<String, Student>();
        stuMap.put("stu1", stu1);
        stuMap.put("stu2", stu2);
        model.addAttribute("map", stuMap);
        return "02-list";
    }

    @GetMapping("operation")
    public String testOperation(Model model) {
        //构建 Date 数据
        Date now = new Date();
        model.addAttribute("date1", now);
        model.addAttribute("date2", now);

        return "03-operation";
    }
}